from pyspark.sql.functions import col
from pyspark.sql.session import SparkSession

spark = SparkSession.builder.getOrCreate()

szt_data = spark \
    .read \
    .format("csv") \
    .schema(
    "car_no String,card_no String,close_date String,company_name String,conn_mark int,deal_date String,deal_money DECIMAL(10,2),deal_type String,deal_value DECIMAL(10,2),equ_no String,station String") \
    .load("C:\\Users\\shujia36\\Desktop\\soft\\第二阶段\\数据仓库\\szt_data.txt")

order_by_df = szt_data.orderBy(col("deal_date").asc())

order_by_df \
    .coalesce(1) \
    .write \
    .format("json") \
    .save("C:\\Users\\shujia36\\Desktop\\soft\\第二阶段\\数据仓库\\szt_data_json")
